﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;

namespace HBSRWebApi.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class SendDataController : ControllerBase
    {

        private readonly IHubContext<hpcpdi.ChatHub.MyHub> _hubContext;
        public SendDataController( IHubContext<hpcpdi.ChatHub.MyHub> hubContext)
        {
           

            this._hubContext = hubContext;
            //init();
        }
        ///发送数据方法
        private void sendDataMethod(string key, string result)
        {
            _hubContext.Clients.All.SendAsync("Show", key, result).Wait();
        }

        [HttpGet]
        public async Task SendMessage(string user, string message)
        {
            await _hubContext.Clients.All.SendAsync("ReceiveMessage", user + "[" + DateTime.Now.ToLongTimeString() + "]", message);
        }
        //public async Task SendMessageToUser(string user, string message)
        //{
        //    await _hubContext.Clients.Client(Context.ConnectionId).SendAsync("ReceiveMessage", user + ":" + DateTime.Now.ToLongTimeString() + "]", message);
        //}



    }
}
